<%+header%>

<%
	local uci = require("luci.model.uci").cursor()
	local net = require "luci.model.network".init()
	local fs = require "nixio.fs"
	local sys = require "luci.sys"
	local ut = require "luci.util"
	local ifaces = sys.net:devices()
	local servers_ip = {}
	local server_ip = uci:get("shadowsocks-libev","sss0","server")
	if server_ip == '127.0.0.1' then
		local upstreams = uci:get("nginx-ha","ShadowSocks","upstreams")
		for _, up in pairs(upstreams) do
			local a = up:match("^([^:]+):")
			table.insert(servers_ip,a)
		end
	else
		table.insert(servers_ip,server_ip)
	end
%>
<script type="text/javascript" src="<%=resource%>/cbi.js?v=git-18.243.49640-2f13420" data-strings="{&#34;path&#34;:{&#34;resource&#34;:&#34;\/luci-static\/resources&#34;,&#34;browser&#34;:&#34;\/cgi-bin\/luci\/admin\/filebrowser&#34;}}"></script>
<script src="/luci-static/resources/xhr.js?v=git-18.324.48426-65adb4e"></script>
<script>
	function jsshowadv() {
		if(document.getElementById('showadv').checked){
			document.getElementById('advancedsettings').style.display='inline';
		} else {
			document.getElementById('advancedsettings').style.display='none';
		}
	}
</script>
<% if stderr and #stderr > 0 then %><pre class="error"><%=pcdata(stderr)%></pre><% end %>
<form class="inline" method="post" action="<%=url('admin/system/status/server_add')%>" enctype="multipart/form-data">
    <div class="cbi-map">
	<h2 name="content"><%:Wizard%></h2>
	<fieldset class="cbi-section" id="server">
	    <legend><%:Server settings%></legend>
	    <%
		nbserver=0
		uci:foreach("openmptcprouter","server", function(s)
			nbserver=nbserver+1
		end)
		uci:foreach("openmptcprouter","server", function(s)
		    servername = s[".name"]
	    %>
	    <div class="cbi-section-remove right">
		<input type="hidden" name="server.<%=servername%>" value="<%=servername%>" />
	    </div>
	    <h3><%=servername%></h3>
	    <div class="cbi-section-node" id="cbi-omr-wizard-<%=servername%>">
		<div class="cbi-value">
		    <label class="cbi-value-title" for="server_ip"><%:Server IP%></label>
		    <div class="cbi-value-field">
			    <input name="<%=servername%>.server_ip" id="<%=servername%>.server_ip" placeholder="<%:Server IP%>" class="cbi-input-text" value="<%=uci:get("openmptcprouter",servername,"ip")%>" data-optional="false">
			<div class="cbi-value-description">
			    <%:Server IP%>
			</div>
		    </div>
		</div>
		<br />
		<div class="cbi-value">
		    <label class="cbi-value-title"><%:Server username%></label>
		    <div class="cbi-value-field">
			<input type="text" name="<%=servername%>.openmptcprouter_vps_username" placeholder="<%:Server username%>" class="cbi-input-text" value="<%=uci:get("openmptcprouter",servername,"username")%>" data-optional="false">
			<br />
			<div class="cbi-value-description">
			    <%:API username to retrieve personnalized settings from the server.%>
			</div>
		    </div>
		</div>
		<div class="cbi-value">
		    <label class="cbi-value-title"><%:Server key%></label>
		    <div class="cbi-value-field">
			<input type="text" name="<%=servername%>.openmptcprouter_vps_key" placeholder="<%:Server key%>" class="cbi-input-text" value="<%=uci:get("openmptcprouter",servername,"password")%>" data-optional="false">
			<br />
			<div class="cbi-value-description">
			    <%:Key to configure, retrieve others keys and settings from Server.%>
			</div>
		    </div>
		</div>
	    <%
		end)
	    %>
	    </div>
	</fieldset>
    </div>
    <div class="cbi-page-actions">
	<input type="hidden" name="token" value="<%=token%>" />
	<input class="cbi-button cbi-button-apply" type="submit" value="<%:Save & Apply%>" /> <input class="cbi-button cbi-button-reset" type="button" value="Reset" onclick="location.href='<%=url('admin/system/status/server')%>'" />
    </div>
</form>
<script type="text/javascript">cbi_init();</script>
<%+footer%>
